home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 20 / Cream of the Crop 20 (Terry Blount) (1996).iso / program / commio0b.zip / TASKUNIT.PAS < prev    next >
Pascal/Delphi Source File  |  1996-05-14  |  14KB  |  354 lines

  1. {$O-,F+}   {must not be overlayed; but should be far for most procedures.}
  2. unit TASKunit;
  3. {
  4.           This unit is a companion to the COMMIO communications unit.
  5.                 Written by Jason Morriss a.k.a. Lief O'Pardy
  6.  
  7.                   Copyright (C) 1995,1996 by Jason Morriss
  8.  
  9.   This is the TASK unit.  This unit contains the tasks to be used when the
  10.   door runs.  Each Task "Multi-Tasks" with the main program, all of which is
  11.   controlled by "Switch_Task" (meaning this is not interrupt driven).  Most
  12.   of the routines in the COMMIO package will do switches on ther're own.  But
  13.   if you create your own routines that have medium/long periods of time where
  14.   they do not call any IO routines in the COMMIO unit then you should add
  15.   the "switch_task" procedure to your routines as well.  Its easy, and i
  16.   don't want you to get discouraged about this.  Look at some of the routines
  17.   in the COMMIO unit (readkey, write/ln, etc) for examples in action...
  18.   This unit sets up the following tasks:
  19.     Time_Task: Updates the time variables for the user.  (How long the user
  20.                has been on; how much time is left for the user in the door)
  21.                If the user's time expires, a message is displayed to the
  22.                user then the door is HALTed immediately, No matter what the
  23.                program was doing.  Then the ExitChain starts. (more details
  24.                are below)
  25.     Stat_Task: Updates the statusbar on the bottom of the local screen.  The
  26.                only thing that gets updated on it, is the time (if
  27.                UpdateStatusBar=True).  You can change how the status bar
  28.                looks, really easily (but that requires a recompilation).
  29.     CD_Task  : Detects when the carrier is lost.  If the carrier is lost, or
  30.                if door.online=false then the door is HALTed immediately, No
  31.                matter what the program was doing.  Then the ExitChain starts.
  32.  
  33.     You can also put your own tasks into this unit.  Just don't make the
  34.     procedure too large, its kinda like creating an interrupt procedure,
  35.     it should take the LEAST amount of time possible to complete its task
  36.     (unless you have multiple switch_task calls in the procedure).
  37.     Inside the procedure should be an endless repeat until..loop, and thats
  38.     where ALL of your code for that procedure should be located.  Because if
  39.     the procedure exits, then it will be removed from the Task list, and will
  40.     not be called again, unless you "install" it again.  But if you want it
  41.     to do that, thats fine too.  Look at the procedures that are already
  42.     created below to see what i mean, if you don't understand.  A procedure
  43.     can still be removed from the task list using Kill_Task() in the MTASK
  44.     unit.
  45.  
  46.     This unit also contains all the "Sysop Keys".  I have created a default
  47.     set that should meet the requirements of almost any door game.  You can
  48.     alter the ones given, or add more of your own, or you dont have to use
  49.     any at all, ... up to you.
  50.  
  51.     If any procedure halts the program, this is what happens:
  52.       The program is stopped wherever it is, then the ExitChain will go
  53.       through all procedures in the chain.  If you have something that MUST
  54.       be run before the door returns to the BBS, then it would be wise to put
  55.       that procedure into the ExitChain, That way the procedure will always
  56.       be called, even if the user drops carrier (or if a runtime error
  57.       occurs).  Look in the _EXIT unit for more info on setting up a
  58.       procedure in the ExitChain.  Doing this is almost a requirement for any
  59.       door game, since most doors need to save some sort of info on the user
  60.       to disk, but if the user were to get disconnected (coughhangupcough) or
  61.       something, then everything that user did during his/her session will be
  62.       lost.
  63. }
  64. interface
  65.  
  66. uses crt, dos, async, commio, doorio, syskeys, mtask;
  67.  
  68.  
  69. Procedure InstallAllTasks;
  70. {^ Installs all of the tasks created in this unit.  If ANY ONE of the tasks
  71.    does not install because of not enough memory, or some other error, then
  72.    the DOOR will terminate, because most of the tasks ARE needed for proper
  73.    operation of the DOOR (time variables). }
  74.  
  75. {Procedure InstallSysopKeys;{}
  76. {^ Installs all the Default Sysop Keys (Fkeys).  These can be modified anyway
  77.    you need them to be.  This is called automatically in _THIS_ units' init
  78.    section below. }
  79.  
  80. implementation
  81.  
  82. var
  83.   useless:byte;
  84.  
  85. {$F+} {most (if not all) of these procs need to be far. incase i forget the
  86.        "far" word somewhere below, on a FAR procedure...}
  87. {───────────────────────────────────────────────────────────────────────────}
  88. Procedure F1Key(var p); far;
  89. {F1: help key, displays functions of all sysop keys to the sysop.  Remember,
  90.      none of the text here gets sent to the remote side, and the cursor stays
  91.      with whatever the user is doing (all of the text written here, uses
  92.      direct screen writes; which doesn't move the cursor), and will not mess
  93.      up the color for the remote user. }
  94. var
  95.   key : char absolute p;
  96.   sy,x,y,i,a : byte;
  97.   oldmem : longint;
  98.   ch : char;
  99.   oinput,done : boolean;
  100.   fs : string[11];
  101. begin
  102. {  door.updatelocal:=false;{}
  103.   oinput:=door.localinputON;
  104.   door.localinputON:=false;{}
  105.  
  106.   {v- prepare the screen for the help box}
  107.   x:=wherex; y:=wherey;
  108.   if door.UpdateStatusBar
  109.     then sy:=door.StatusBarY-6
  110.     else sy:=door.StatusBarY-4;
  111.   if y>=sy then begin
  112.     if door.updatestatusbar
  113.       then gotoxy(1,door.StatusBarY-1)
  114.       else gotoxy(1,door.StatusBarY);
  115.     while y>=sy do begin
  116.       writeln; dec(y);
  117.     end;
  118.   end;
  119.   window(1,1,80,sy-1);
  120.   gotoxy(x,y);
  121.  
  122.   if door.comport>0 then begin
  123.     if door.whichio=internalio then
  124.       if C_fifook[door.comport] then fs:='Enabled    ' else fs:='Disabled   '
  125.     else fs:='Fossil mode';
  126.   end else fs:='Local mode ';
  127.  
  128.   {v- draw help box locally}
  129.   Writestr(1,sy+0,'Θ8Θb╒══════════════════════════════════════════════════════════════════════════════╕');
  130.   WriteStr(1,sy+1,'Θ8Θb│ Θ7F1 Θ9:Θ3 This help box        Θ7F4 Θ9:Θ3 -5 min. to user time   Θ9│Θ3 Memory: '+
  131.                   padestr(istr(maxavail,0),' ',6)+' bytes Θ8│');
  132.   WriteStr(1,sy+2,'Θ8Θb│ Θ7F2 Θ9:Θ3 Toggle Status Bar    Θ7F5 Θ9:Θ3 Chat with user         Θ9│Θ3 FIFOS: '+fs+'   Θ8│');
  133.   WriteStr(1,sy+3,'Θ8Θb│ Θ7F3 Θ9:Θ3 +5 min. to user time Θ7F6 Θ9:Θ3 Kick user out of DOOR! Θ9│Θ3                      Θ8│');
  134.   if door.updatestatusbar then begin
  135.     WriteStr(1,sy+4,'Θ8Θb├────────┬────────────┬─────────────────────────┬──────────────────────┬───────┤');
  136.     WriteStr(1,sy+5,'Θ8Θb│Θ3timeleftΘ8│Θ3connect infoΘ8│Θ3current user online      Θ8│Θ3local environment     Θ8│Θ3dduuhh!Θ8│')
  137.   end else begin
  138.     WriteStr(1,sy+4,'Θ8Θb╘══════════════════════════════════════════════════════════════════════════════╛');
  139.   end;
  140.  
  141.   oldmem:=MaxAvail;
  142.   done:=false;
  143.   repeat
  144.     if MaxAvail<>oldmem then begin
  145.       WriteStr(67,sy+1,padestr(istr(maxavail,0),' ',6));
  146.       oldmem:=MaxAvail;
  147.     end;
  148.     switch_task
  149.   until keypressed;            {local keypresses only!}
  150.   while keypressed do readkey; {"}
  151.  
  152.   {v- clean up}
  153.   x:=wherex; y:=wherey;
  154.   a:=textattr; textattr:=7;                   {dont disturb the user's color}
  155.   if door.updatestatusbar then begin
  156.     window(1,sy,80,door.StatusBarY-1); clrscr;
  157.     window(1,1,80,door.StatusBarY-1);
  158.   end else begin
  159.     window(1,sy,80,door.StatusBarY); clrscr;
  160.     window(1,1,80,door.StatusBarY);
  161.   end;
  162.   textattr:=a;                                {"}
  163.   gotoxy(x,y);
  164.  
  165.   door.localinputON:=oinput;
  166.   syskey1[key].open:=false;
  167. end;
  168. {───────────────────────────────────────────────────────────────────────────}
  169. Procedure FunctionKeys(var p); far;
  170. {This handles all of the Fkey operations found on the F1 help box}
  171. var b1,b2:boolean; ch:char;
  172. begin
  173.   case char(p) of
  174.     F2 : if door.UpdateStatusBar then begin
  175.       door.UpdateStatusBar:=false;
  176.       HideStatusBar;
  177.     end else begin
  178.       door.UpdateStatusBar:=true;
  179.       ShowStatusBar;
  180.     end;
  181.     F3 : begin
  182.       inc